const companiesService = require('../services/companiesService')


exports.getCompanies = async (req,res) =>{
    try {
        const result = await companiesService.findAllCompanies();
        res.json(result);
    } catch (error) {
        res.status(500).json({error:error.message})
    }
}

exports.getCompanyById = async (req,res) =>{
    try {
        const result =await companiesService.finCompaniesById(req.params.id);
        res.json(result);
    } catch (error) {
        res.error({error:error.message});
    }
}

exports.createCompany = async (req,res) =>{
    try {
        const result = await companiesService.createCompany(req.body);
        res.status(201).json(result);
    } catch (error) {
        res.status(400).json({error:error.message})
    }
}

exports.updateCompany = async (req,res) =>{
    try {
        const result = await companiesService.updateCompany(req.params.company_id,req.body);
        res.json(result);
    } catch (error) {
        const statusCode = error.message === 'Job not found' ? 404 : 400;
        res.status(statusCode).json({error:error.message});
    }
}

exports.updateCompanyLogo = async (req,res) => {
    try {
        await companiesService.updateCompanyLogo(req.body);
        res.status(200).json('OK');
    } catch (error) {
        res.json({error:error.message});
    }
}